//
//  UIButton+ACEBadge.m
//  ACE
//
//  Created by zhangtao on 2018/8/8.
//  Copyright © 2018年 zt.td. All rights reserved.
//

#import "UIButton+ACEBadge.h"

@implementation UIButton (ACEBadge)

-(void)showBadgeWithNum:(NSInteger)num{
    
  
    
//    UILabel *lab = self.titleLabel;
    CGRect frame = self.frame;
    UILabel *badgeLab = [[UILabel alloc]initWithFrame:CGRectMake(frame.size.width-5, 0, 10, 10)];
    [badgeLab setTag:1000];
    badgeLab.backgroundColor = [UIColor redColor];
    badgeLab.textAlignment = NSTextAlignmentCenter;
    badgeLab.font = [UIFont systemFontOfSize:10];
    badgeLab.text = [NSString stringWithFormat:@"%ld",num];
    badgeLab.textColor = [UIColor whiteColor];
    badgeLab.layer.cornerRadius = 5;
    badgeLab.layer.masksToBounds = YES;
    
    [self addSubview:badgeLab];
    NSLog(@"......");
    
  
}

-(void)showBigStateWithFont:(NSInteger)font{
    self.titleLabel.font = [UIFont systemFontOfSize:font];

    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[UILabel class]] && view.tag == 1000) {
            UILabel *lab = (UILabel *)view;
//            CGRect frame = CGRectMake(lab.frame.origin.x-5, lab.frame.origin.y, lab.frame.size.width+5, lab.frame.size.height+5);
            dispatch_async(dispatch_get_main_queue(), ^{
                CGPoint centerP = self.center;
                [self sizeToFit];
                self.center = centerP;
                lab.font = [UIFont systemFontOfSize:14];
                lab.frame = CGRectMake(self.frame.size.width-7, 0, 14, 14);
                lab.layer.cornerRadius = 7;
            });
           

        }
    }
}

-(void)showNormalStateWithFont:(NSInteger)font{
    self.titleLabel.font = [UIFont systemFontOfSize:font];

    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[UILabel class]] && view.tag == 1000) {
            UILabel *lab = (UILabel *)view;
//            CGRect frame = CGRectMake(lab.frame.origin.x+5, lab.frame.origin.y, lab.frame.size.width-5, lab.frame.size.height-5);
//            lab.frame = frame;
            
            dispatch_async(dispatch_get_main_queue(), ^{
                CGPoint centerP = self.center;
                [self sizeToFit];
                self.center = centerP;
                lab.font = [UIFont systemFontOfSize:10];
                lab.frame = CGRectMake(self.frame.size.width-5, 0, 10, 10);
                lab.layer.cornerRadius = 5;
            });
         
        }
    }
}

@end
